﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// Additional imports
using System.Web.Security;
using MyNamespace;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.IsAuthenticated)
            this.ExistingUsers.Visible = true;
        else
            this.ExistingUsers.Visible = false;
    }

    protected void ExistingUsers_SelectedIndexChanged(object sender, EventArgs e)
    {
        /* Steps to handle friendship requests
         * 1) If not already a friend, then add as a friend
         * 2) If already a friend, then display message to user
         */
        //if(MembershipController.IsFriend(
        Guid myUserID = (Guid) (System.Web.Security.Membership.GetUser(this.User.Identity.Name).ProviderUserKey);
        Guid friendID = (Guid) this.ExistingUsers.SelectedDataKey.Value;
        if (MembershipController.IsFriend(myUserID, friendID))
            this.MessageLabel.Text = "The selected user is already a friend";
        else
        {
            MembershipController.AddFriend(myUserID, friendID);
            this.MessageLabel.Text = "The selected user was added as a friend";
        }
    }
}
